package chapter11.exercise.test15;

import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedList;

import com.common.utils.Stack;

public class Test15 {

    @SuppressWarnings("unchecked")
    public static void main(String[] args) {
        String ex = "+U+n+c---+e+r+t---+a-+i-+n+t+y---+-+r+u--+l+e+s---";
        LinkedList cs = new LinkedList();
        Collections.addAll(cs, ex.toCharArray());
        Iterator iterator = cs.iterator();
        Stack<Character> stack = new Stack<>();
		/*while(iterator.hasNext()){
			Character next = (Character)iterator.next();
			if(next == '+'){
				stack.push(new Character((char) iterator.next()));
			} else if(next == '-'){
				if(!stack.empty()){
					System.out.println(stack.pop());
				}
			}
		}*/
        char[] chars = ex.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            char c = chars[i];
            if (c == '+') {
                System.out.println("push: " + chars[++i]);
                stack.push(chars[i]);
            } else if (c == '-') {
                if (!stack.empty()) {
                    System.err.println("pop: " + stack.pop());
                } else {
                    System.err.println("stack empty");
                }
            }
        }
        System.out.println(stack);
    }
}
